package com.lsa.letcode.common;

import static org.junit.Assert.*;

import java.io.InputStream;

import org.junit.Test;

import com.lsa.iview.trees.BinaryTree;
import com.lsa.iview.trees.BinaryTreeUtils;
import com.lsa.iview.trees.BinaryTree.Node;

public class TreeUtilsTest {
	@Test
	public void testCopyTree() throws Exception {
		InputStream in = TreeUtilsTest.class.getResourceAsStream("treeUtilsTest.tgf");
		BinaryTree<Integer> t1 = BinaryTreeUtils.fromTgf(in);
		TreeNode n2 = TreeUtils.copyAdaptTree(t1.getRoot());
		assertTrue(TreeUtils.areEqual(t1.getRoot(), n2));
	}
	
	@Test
	public void testCopyTree2() throws Exception {
		InputStream in = TreeUtilsTest.class.getResourceAsStream("treeUtilsTest.tgf");
		TreeNode n1 = TreeUtils.fromTgf(in);
		Node<Integer> n2 = TreeUtils.copyAdaptTree(n1);
		assertTrue(TreeUtils.areEqual(n1, n2));
	}
	
	@Test
	public void testName() throws Exception {
		InputStream in = TreeUtilsTest.class.getResourceAsStream("treeUtilsTest2.tgf");
		TreeNode n1 = TreeUtils.fromTgf(in);
		System.out.println(BinaryTreeUtils.toString(TreeUtils.copyAdaptTree(n1)));
		
	}
}
